package com.kandinfo.isbnmanage.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;

import com.kandinfo.base.common.repository.BaseRepository;
import com.kandinfo.isbnmanage.domian.IsbnOrder;

public interface IsbnOrderRepository extends BaseRepository<IsbnOrder, Long> {
	
	@Query(value="select count(distinct order_num) from isbn_order where barcode = ?1 and status != 0 and status != 6  and order_num is not null" ,nativeQuery=true)
	Integer countWithOrder(String barcode);
	
	@Query(value="select count(id) from isbn_order where barcode = ?1 and status != 0 and status != 6 and order_num is null " ,nativeQuery=true)
	Integer countWithoutOrder(String barcode);
	
	@Query(value="select count(distinct order_num) from isbn_order where barcode = ?1 and status= ?2 and order_num is not null " ,nativeQuery=true)
	Integer countWithOrderByStatus(String barcode,Integer status);
	
	@Query(value="select count(id) from isbn_order where barcode = ?1 and status= ?2 and order_num is null " ,nativeQuery=true)
	Integer countWithoutOrderByStatus(String barcode,Integer status);
	
	@Query(value="select * from isbn_order where barcode = ?1" ,nativeQuery=true)
	List<IsbnOrder> get(String barcode);

	@Query(value="select * from isbn_order where barcode = ?1 and isbn_information_id = ?2", nativeQuery=true)
	IsbnOrder get(String barcode, Long informationId);
}
